package com.effectiv.crm.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.authentication.UserCredentials;
import org.springframework.data.mongodb.config.AbstractMongoConfiguration;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;

import com.mongodb.Mongo;
import com.mongodb.WriteConcern;

@Configuration
@EnableMongoRepositories("com.effectiv.crm.repository")
public class MongoConfiguration extends AbstractMongoConfiguration{

	@Override
	protected String getDatabaseName() {
		return "crm";
	}

	@Override
	public Mongo mongo() throws Exception {
		Mongo m = new Mongo();
		m.setWriteConcern(WriteConcern.SAFE);
		return m;
	}
	
	
	
	
	@Override
	@Bean
	public SimpleMongoDbFactory mongoDbFactory() throws Exception {
		//return new SimpleMongoDbFactory(mongo(), getDatabaseName(), new UserCredentials("admin", "admin1612"));
		return new SimpleMongoDbFactory(mongo(), getDatabaseName());
	}

	@Override
	protected String getMappingBasePackage() {
		
		return "com.effectiv.crm.domain";
	}

	
}
